$(function(){
	var dataJson= [];
	$.ajax({
		url:$WEB_ROOT_PATH+"/Agreement/getAgreementList.json",
		type:"post",
		async: false, 
		data: JSON.stringify({"userName":'',"agreementId":GetQueryString("id")}),
		contentType: "application/json",
		dataType:"json",
		success:function(result){
			dataJson = result.data.agreementList;
		}
	})
	var rentcoust = parseInt(dataJson[0].clothingRent/dataJson[0].count);
	$("#rentcoust").html(rentcoust);
	var leaseTime = new Date(dataJson[0].leaseTime);
	var returnTime = new Date(dataJson[0].returnTime);
	var days = GetDateDiff(leaseTime,returnTime);
	
	//$("#name").html(username);
	
	$("#restoreYear").html(leaseTime.getFullYear());
	$("#restoreMonth").html(leaseTime.getMonth());
	$("#restoreDay").html(leaseTime.getDate());
	
	$("#leaseYear").html(returnTime.getFullYear());
	$("#leaseMonth").html(returnTime.getMonth());
	$("#leaseDay").html(returnTime.getDate());

	
	$("#days").html(days);
	
	$("#nameCostomer").html(dataJson[0].userName);
	$("#count").html(dataJson[0].count);
	$("#coust").html(dataJson[0].clothingPrice);
	$("#totle").html(dataJson[0].clothingRent);
	$("#yajin").html(dataJson[0].foregift);
	$("#clothingName").html(dataJson[0].clothingName);
	
	
	/*if(myurl !=null && myurl.toString().length>1)
	{
	  GetQueryString("id")
	}*/
	html2canvas($("#myCanvas"), {   
        onrendered: function(canvas) {  
            $('#down_button').attr('href', canvas.toDataURL());  
            $('#down_button').attr('download', 'myjobdeer.png');  
            
            var html_canvas = canvas.toDataURL();  
            $.post('', {   
                order_id: 1,  
                type_id: 2,  
                html_canvas: html_canvas  
            }, function(json) {}, 'json');   
        }   
    });
	
})
function GetDateDiff(leaseTime,returnTime)  
{  
	 var date1 = leaseTime.getMonth()+"-"+leaseTime.getDate()+"-"+leaseTime.getFullYear();  
     var date2 = returnTime.getMonth()+"-"+returnTime.getDate()+"-"+returnTime.getFullYear();  
   
     //讲时间字符串转化为距离1970年1月1日午夜零时的时间间隔的毫秒数  
     var time1 = Date.parse(date1);  
     var time2 = Date.parse(date2);  
       
     //讲两个时间相减，求出相隔的天数  
     var dayCount = (Math.abs(time2 - time1))/1000/60/60/24;  
     return  dayCount;    
}

function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null){
    	 return  unescape(r[2]);
     }
     return null;
}